package com.example.shop_2302.adapter

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.ExplosiveMoney
import com.example.shop_2302.R

class MoneyAdapter:BaseQuickAdapter<ExplosiveMoney,BaseViewHolder>(R.layout.item_money) {
    var selectType = 4//默认选中的分类的值为4
    override fun convert(holder: BaseViewHolder, item: ExplosiveMoney) {
        holder.setText(R.id.money_info,item.info)
        holder.setText(R.id.meney_name,item.name)
        //选中的为红色，未选中的为黑色
        if(selectType==item.type.toInt()){
            holder.getView<TextView>(R.id.money_info).setTextColor(Color.RED)
            holder.getView<TextView>(R.id.meney_name).setTextColor(Color.RED)
        }else{
            holder.getView<TextView>(R.id.money_info).setTextColor(Color.BLACK)
            holder.getView<TextView>(R.id.meney_name).setTextColor(Color.BLACK)
        }
    }
    //点击分类时，调用此方法。更新selectType的值
    fun updateType(type:Int){
        selectType = type
        notifyDataSetChanged()//刷新适配器，重新加载数据
    }
}